﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Peninsula.DataAccess
{
    [Serializable]
    public  abstract class BaseEntity
    {
        #region 构造函数

        /// <summary>E:\实训\实训代码\Express.Web\Express.DataAccess\EntityBase.cs
        ///     数据实体基类
        /// </summary>
        protected BaseEntity()
        {
            IsDeleted = false;
            CreatedTime = DateTime.Now;
            UpdatedTime = DateTime.Now;
            Id = Guid.NewGuid().ToString();
            UpdatedBy = "系统";
            CreatedBy = "系统";
        }


        #endregion

        public void SetUpdateInfo(string updateBy)
        {
            UpdatedBy = updateBy;
            UpdatedTime = DateTime.Now;
        }

        public void SetCreateInfo(string createBy)
        {
            CreatedBy = createBy;
            CreatedTime = DateTime.Now;
        }

        public void SetCreateAndUpdateInfo(string changeBy)
        {
            UpdatedBy = CreatedBy = changeBy;
            UpdatedTime = CreatedTime = DateTime.Now;
        }

        #region 属性

        [Key]
        [Display(Name = "id")]
        [StringLength(50)]
        public virtual string Id { get; set; }

        /// <summary>
        ///     获取或设置 获取或设置是否禁用，逻辑上的删除，非物理删除
        /// </summary>
        [Display(Name = "是否删除")]
        public bool IsDeleted { get; set; }

        [Display(Name = "创建时间")]
        public DateTime CreatedTime { get; set; }

        [Display(Name = "修改时间")]
        public DateTime? UpdatedTime { get; set; }

        [Display(Name = "修改人"), Required, StringLength(50)]
        public string UpdatedBy { get; set; }

        [Display(Name = "创建人"), Required, StringLength(50)]
        public string CreatedBy { get; set; }


        #endregion
    }
}
